﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ruici.Web.Services.ServiceForWeb;
using System.Data;
using Ruici.Web.Services.sms;

namespace Ruici.Web.Services
{
    public class UserService
    {
        private ServiceForWebSoapClient soupService = new ServiceForWebSoapClient("ServiceForWebSoap");
        private SMSSoapClient smsService = new SMSSoapClient("SMSSoap");

        public string Login(string sUserID, string sPassword)
        {
            string resultDataSet = soupService.CRM_WEB_Login(sUserID, sPassword);
            return resultDataSet;
        }

        public DataSet GetRegisteredWebUser(string sUserID,string sPassword)
        {        
            DataSet resultDataSet = soupService.CRM_WEB_LoginWebUser(sUserID, sPassword);
            return resultDataSet;
        }

        public string AddRegisteredWebUser(string sMobile,string sName,string sGender, string sPhoto,string sUserId, string sPassword)
        {
            string resultCode = soupService.CRM_WEB_RegisterWebUser(sMobile, sName, sGender, sPhoto, sUserId, sPassword, "").Code;
            return resultCode;
        }

        public int UpdateUserInforWithCert(Member UserInfo, string certTypeCode, string certNo)
        {
            int iUpdateResult = soupService.CRM_WEB_UpdatePersonBaseWithCert(UserInfo,certTypeCode,certNo);

            return iUpdateResult;
        }

        public Member GetMemberInforByPID(int sPID)
        {
            return (Member)soupService.CRM_WEB_GetMemberInfoByPid(sPID)[0];
        }

        public WebAccount GetWebAccountByUserId(string userid)
        {
            return soupService.CRM_WEB_GetWebAccountByUserName(userid);
        }

        public int ChangePassword(string userid, string sNewPassword)
        {
            return soupService.CRM_WEB_ChangePassword(userid, sNewPassword);
        }

        public string RetriveUserPassword(string sMobile)
        {
            return soupService.CRM_WEB_RetrieveWebUserPwd(sMobile);
        }

        public WebAccount GetWebAccountByMobile(string sMobile)
        {
            return soupService.CRM_WEB_GetWebAccountByMobile(sMobile);
        }

        public void SendSMSMessage(string sMobile,string sMessage)
        {
            smsService.sendMsg(sMobile, sMessage);
        }
    }
}
